20. Exercise: AsyncTaskLoader in Sunshine

Adding AsyncTaskLoader to Sunshine

In this Exercise, you'll update Sunshine to use an AsyncTaskLoader instead of FetchWeatherTask.

Exercise Code

Exercise:S05.01-Exercise-AsyncTaskLoader

Updating Sunshine to use AsyncTaskLoader

Let's update Sunshine, replacing the FetchWeatherTask with an AsyncTaskLoader.

SOLUTION:
  • Have MainActivity implement the loader callbacks
  • Create a loader ID
  • Fill out the loader callbacks using the code from FetchWeatherQuery
  • Call initLoader in onCreate (whether or not the loader already exists)
  • Restart the loader if refresh is triggered from the menu